/*
 * Instruction3D.java
 *
 * Created on March 22, 2007, 9:26 PM
 *
 *
Restores context at the end of a subroutine. Loads the program counter
with a 16-bit value pulled from the stack and increments the stack pointer
by two. Program execution continues at the address restored from the
stack.
 */

package moto9s12sim;

/**
 *
 * @author Fergus Earnshaw
 */
public class Instruction3D extends Instruction {
    
    /** Creates a new instance of Instruction3D */
    public Instruction3D() {
        this.strAssemblyCode = "RTS";
        this.bCodes = new byte[1];
        this.bCodes[0] = (byte)Integer.parseInt("3D",16);
    }
    
    public boolean excute(M9S12 cpu)
    {
        this.shAddr = cpu.PC.getRegister();
        cpu.PC.inc();

        byte bPageH, bPageL;
        //TO DO CODE INSTRUCTION
        //(M(SP) : M(SP+1)) => PCH : PCL; (SP) + $0002 => SP
        
        bPageH = cpu.bMemory[cpu.SP.getUnsignedRegister()];
        cpu.SP.inc();
        bPageL = cpu.bMemory[cpu.SP.getUnsignedRegister()];
        cpu.SP.inc();
        
        cpu.PC.setRegister(bPageH, bPageL);
        
        printInstruction(cpu);
        //I think the first invalid instruction should halt excution
        return true;
    }  
    
}